package classes.multithread;

import org.junit.Test;

/**
 * @author : DuJiabao
 * @Date : 2021/1/20 17:19
 * @Project : java_learning
 * @File : null.java
 * @Desc : 单例模式，懒汉式
 */
public class SingletonSaved {
    private SingletonSaved() {
    }

    private static SingletonSaved instance = null;

    public static SingletonSaved getInstance() {
        if (instance == null) {  // 保证后续无需准寻同步
            synchronized (SingletonSaved.class) {  // 保证只创建一个实例
                if (instance == null) { // 避免重复添加
                    instance = new SingletonSaved();
                }
            }
        }
        return instance;
    }
}



